package com.spring.demo.weixinpay.controller;


import com.spring.demo.weixinpay.service.RedPacketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

@Controller
@RequestMapping(value = "/redpacket")
public class RedpacketController {
    private Logger logger= Logger.getLogger(this.getClass());
    
    @Autowired
    private RedPacketService redPacketService;
    
    @RequestMapping("/sendxml")
    @ResponseBody
    public String sendXML(HttpServletRequest request, HttpServletResponse response){
        String openid = request.getParameter("openid");
        Map<String, String> map=new HashMap<>();
        try {
            map = redPacketService.sendXml(openid);
        }catch (Exception e){
            e.printStackTrace();
        }
        if (map.get("return_code").equals("SUCCESS")){
            logger.info("---支付成功！---");
            return "SUCCESS";
        }else{
            logger.info("---支付失败！---");
            return  "FAIL";
        }
    }

    /*public static void main(String[] args)throws Exception{
        RedPacketServiceImpl redPacketService1=new RedPacketServiceImpl();
        Map<String, String> patters = redPacketService1.sendXml("123456");
        System.out.println("result"+patters.get("result_code"));
    }*/
}
